<?php
$page_type = "A";
require_once 'header.php';

// Obtain information for the record to be updated
$fname = $_POST["fname"];
$lname = $_POST["lname"];
$sid = $_POST["sid"];
$student_type = $_POST["student_type"];
$probation = $_POST["probation"];
$grade = $_POST["grade"];
$cno = $_POST["cno"];
$seqid = $_POST["seqid"];

// Student type
if ($student_type == "U")
  $stflag = "0";
else if ($student_type == "G")
  $stflag = "1";
else
  $stflag = " ";

// Probation status
if ($probation == "y")
  $pflag = "1";
else if ($probation == "n")
  $pflag = "0";
else 
  $pflag = " ";

$sql = "update CLIENT set Fname='$fname', Lname='$lname', STFlag='$stflag', PFlag='$pflag' where Sid='$sid'";

$result_array = execute_sql_in_oracle($sql);
$result = $result_array["flag"];
$cursor = $result_array["cursor"];

if (!$result){
  // Store fields for update form
  $_SESSION['fname'] = $fname;
  $_SESSION['lname'] = $lname;
  $_SESSION['sid'] = $sid;
  $_SESSION['student_type'] = $student_type;
  $_SESSION['input_grade'] = $grade;
  $_SESSION['input_cno'] = $cno;
  $_SESSION['input_seqid'] = $seqid;
  $_SESSION['input_pflag'] = $probation;
  
  $update_error = 'Student ID('."<b><font color=\"black\">".$sid."</font></b>".') update failed!';
  header("Location:student_update.php?update_error=$update_error");
}
else {
  // Record updated, redirect to student.php
  resetForm();
  $_SESSION['sid'] = "";
  $update_success = 'Student ID('."<b><font color=\"black\">".$sid."</font></b>".') updated successfully!';
  header("Location:student.php?update_success=$update_success");
}
?>